home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / cnews013.zip / CNEWS013.NWS < prev    next >
Text File  |  1988-12-29  |  69KB  |  1,473 lines

  1.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  2.  
  3.      *-------------------------------------------------------------*
  4.      |  C  NEWS - International C Electronic Newsletter/Journal    |
  5.      |           "Dedicated to the Art of C Programming"           |
  6.      |                                                             |
  7.      |                     Founded 12/27/87                        |
  8.      *-------------------------------------------------------------*
  9.  
  10.      Table of Contents
  11.  
  12.      The Heap: Messages from the Editor  ..........................2
  13.      by Barry Lynch
  14.      Book Review: Software Engineering in C  ......................5
  15.      by Barry Lynch
  16.      Magazine Review: Circuit Cellar Ink ..........................7
  17.      by Barry Lynch
  18.      Compression Utilities: One Sysop's View  .....................8
  19.      by Barry Lynch
  20.      Commentary:  ................................................10
  21.      by Arnie Cherdak
  22.      Program Design: A Utility: OpusGraf  ........................12
  23.      by Jim Singleton and Barry Lynch
  24.      AWK: An Introduction Part I  ................................16
  25.      By Dan Kozak
  26.      Message Threads from the C BBS:  ............................22
  27.      by Users of the C BBS
  28.           - Changing a File Attribute - Chris Kryza
  29.           - Checking the Size of a Directory - Bob Smith
  30.      Interactive C Graphics: Part I  .............................23
  31.      by Scott Houck
  32.      Article Submission Standards ................................28
  33.      Address's ...................................................29
  34.      Distribution Points .........................................30
  35.      User Response Form ..........................................31
  36.  
  37.           C News is an Electronic Journal published by the C BBS  in
  38.      Burke, VA  on a monthly basis.  The subject for C News is the C
  39.      programming language, as well  as  any  derivatives  like  C++.
  40.  
  41.      All  readers  are  encouraged  to  submit articles, reviews, or
  42.      comments for submission.  C News  is  freely  distributed,  but
  43.      can  not be sold for a profit, or cannot have a charge assessed
  44.      to cover distribution costs.  To do so is in  direct  violation
  45.      of the  License  agreement.  Copies of which are available from
  46.      the C  BBS.    This  publication  is  Copyrighted   under   U.S
  47.      Copyright Law.
  48.  
  49.                                                                        Page  1
  50.  
  51.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  52.      =====================================================================
  53.      THE HEAP:  Messages from the Editor
  54.      =====================================================================
  55.  
  56.      TABLE OF CONTENTS:
  57.  
  58.        - Status of the C BBS
  59.        - What's in this issue of C News
  60.        - User feedback revisited in gentler terms
  61.        - Postcards wanted
  62.        - Software Distribution System (SDS) distribution of C News
  63.        - New feature starting with this issue of C News
  64.        - What is planned for Year 2 of C News
  65.  
  66.     [STATUS OF THE C BBS: OR HOW A HARDISK CRASH MAKES ME FEEL HUMBLE ..]
  67.  
  68.           It's  been  a  long  couple  of  weeks  here at the C BBS, a
  69.      catastrophic hardware failure caused the complete loss of  the  C
  70.      BBS itself.    Luckily,  I had most of the C source files on disk
  71.      and was able to recreate the BBS.  Some minor things  still  need
  72.      to  be  completed,  but the board is operational and once again C
  73.      News is being cranked out on an infrequent basis.
  74.  
  75.          One thing the crash did was delay this issue of C News  by  a
  76.      month or  so.    Instead  of  canvassing  for articles, I was out
  77.      drumming up old C BBS C src files and attempting to get  my  echo
  78.      and netmail  areas  to  work.    No, I did not have a backup, who
  79.      does when it is 80 floppies!!
  80.  
  81.      [WHAT'S IN THIS ISSUE OF CNEWS?]
  82.  
  83.           This issue of C News features  book  and  magazine  reviews,
  84.      also  in  this  issue  three  different  multi-part  articles are
  85.      presented:  Software Design, Interactive  C  Graphics,  and  AWK.
  86.      We  were  blessed  with three seperate projects at the same time,
  87.      and this allows us to split the articles apart and have  material
  88.      for a couple of issues of C News.
  89.  
  90.           This  also  allows you the reader the opportunity to provide
  91.      some feedback to the authors that can be  included  in  a  future
  92.      issue of  C  News!   I hope that you will enjoy these articles as
  93.      much as we have in bringing them to you.
  94.  
  95.      [USER FEEDBACK]
  96.  
  97.           Remember back a few issues in this column, I  mentioned  how
  98.      little feedback  we  were  receiving?    Well  in the last month,
  99.      postcards,  letters  and  electronic  mail  messages  have   been
  100.      arriving from  around  the  globe.    For  instance today, a user
  101.      logged in from Ireland and praised the editors and writers  of  C
  102.      News for  putting  C News together.  This is the sort of feedback
  103.      that we have been looking for, nothing  makes  a  volunteer  feel
  104.      better than  a  nice  compliment  on  his  or  her  efforts.  All
  105.      writers of C  News  are  volunteers  and  a  little  feedback  is
  106.      needed.   Keep  up  the  good  work,  and  keep  those  postcards
  107.  
  108.                                                                     Page  2
  109.  
  110.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  111.  
  112.      coming!
  113.  
  114.      [POSTCARDS WANTED!]
  115.  
  116.           Postcards are still wanted!!  To date  postcards  have  been
  117.      received  from  Arlington,  Virginia,  New  York,  New  York, and
  118.      Montreal, Canada.  So the breakdown to date is:
  119.  
  120.  
  121.              United States                      World
  122.  
  123.                 Virginia                        Montreal, Canada
  124.                 New York
  125.                 Maryland
  126.  
  127.      [SOFTWARE DISTRIBUTION SYSTEM (SDS) DISTRIBUTION OF CNEWS]
  128.  
  129.           C News will begin dsitribution in the Northeast  section  of
  130.      the country  via SDS with this issue.  This is in direct response
  131.      to a netmail message that I received from the coordinator of  SDS
  132.      for the  NE.    This  is  a  big step for C News, as it brings it
  133.      closer to the intended audience.  C News was originally  intended
  134.      for  the  readers  of  the Fidonet C Echomail conference, but has
  135.      grown to be an international electronic journal  that  tranverses
  136.      networks and  systems.    Please  upload C News wherever you can,
  137.      and let's spread the word......
  138.  
  139.      [NEW FEATURE STARTING WITH THIS ISSUE OF CNEWS]
  140.  
  141.           Following in the foot steps of "Byte"  and  "Circuit  Cellar
  142.      Ink",  I  have  decided to place message threads of interest to C
  143.      programmers, from  my  BBS  in  this  newsletter.    This  allows
  144.      users/readers  that  do not log onto the C BBS, the chance to see
  145.      a question and the responses that were received.
  146.  
  147.             The first message  thread  was  started  by  Chris  Kryza,
  148.      concerning  how  to  change  a  file attribute, the second thread
  149.      deals with some floating point problems  during  execution  of  a
  150.      program  in  TurboC,  and the third is a check directory program.
  151.      Enjoy  these  tidbits  and  if  you  see  somthing   that   needs
  152.      correcting or further explanation do not hesitate to ask.
  153.  
  154.      [What is Planned for Year 2, of C News?]
  155.  
  156.           Well,  believe  it  or  not we have almost come full circle.
  157.      Back last December I started C News out  of  the  frustration  of
  158.      reading  the  same  questions  over and over again in the C_Echo.
  159.      Little did I know, or dare to dream that C News as it is  to  day
  160.      would exist.    This is not a commercial product nor will it ever
  161.      be.  It is  not  intended  to  compete  with  the  multitudes  of
  162.      programming  journals  and  magazines  that exist, but compliment
  163.      them.  Let's welcome the new year by giving a hand to  the  users
  164.      of  the  C  BBS and readers of C News that have taken the time to
  165.      contribute!!  <clap, clap, clap>
  166.  
  167.                                                                     Page  3
  168.  
  169.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  170.  
  171.                C News Contributors (1988)
  172.  
  173.  
  174.                David Nugent - Melbourne, Australia
  175.                Marshall Presnell - Parts unknown at the moment
  176.                David Cheslow - Dallas, Texas
  177.                Arnie Cherdak - Silver Spring, Maryland
  178.                Bill Mayne - Silver Spring, Maryland
  179.                Jim Singleton - Arlington, Virginia
  180.                Jerry Zeisler - Herndon, Virginia
  181.                Jack Hess - Dallas, Texas
  182.                Dan Kozak - Arlington, Virginia
  183.                and
  184.                Scott Houck - Washington, D.C.
  185.  
  186.                                                                     Page  4
  187.  
  188.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  189.      ======================================================================
  190.      BOOK REVIEW:  By Barry Lynch
  191.      ======================================================================
  192.  
  193.      Title: Software Engineering in C
  194.      Author: Peter A. Darnell
  195.              Philip E. Margolis
  196.      ISBN Number: 0-387-96574-2
  197.      Publisher:  Springer-Verlag
  198.                  New York-Berlin-Heidelberg
  199.  
  200.           Back in Issue 10 of C News, I  stated  in  the  Book  review
  201.      column:   "The  last  thing  I needed - and my checkbook - was to
  202.      buy another computer book" Well, this is still  the  case  but  I
  203.      can definitely make an exception in with this book.
  204.  
  205.           Rarely  is  it  that  I  can  pick  up  a book, and in a few
  206.      moments know that the book is worth the cover price.    To  often
  207.      in  our profession we are forced to pay good money for books that
  208.      are not worthy of our time.  This is not the case with  "Software
  209.      Engineering in  C".  The title is a tad deceiving, as it seems to
  210.      indicate  that  the  book  is  another  dry  text   on   software
  211.      engineering  principles, of which a few are on the bookcase to my
  212.      right.  < For sake of brevity I will refer to  the  book  in  the
  213.      remainder of  this  document  as  "seC">.    seC is an attempt to
  214.      explain proper software engineering principles using one  of  the
  215.      more popular languages  on  the  market today.  For instance:  In
  216.      Chapter 12 - Software Engineering, sections are included on:
  217.  
  218.               -  Product Specification
  219.               -  Software Design
  220.               -  Project Planning Cost Estimation
  221.               -  Software Tools for Software Production
  222.               -  Debugging Techniques
  223.               -  Testing
  224.               -  Performance Analysis
  225.               -  Documentation
  226.               -  Source Control and Organization.
  227.  
  228.           All topics  that  are  relevant  to  the  software  engineer
  229.      professional.   The  authors  use a "Useful" application to flesh
  230.      out the  ideas  and  concepts  presented  in  the  book:    A   C
  231.      Interpreter.   To  often  in  books  of  this nature, the example
  232.      application given is a "Mailing List  Manager",  or  a  "Graphics
  233.      Menu System".    This  is  a  meaty application for a meaty book.
  234.      Messer's Darnell and Margolis have done an excellent job in  this
  235.      regard.
  236.  
  237.           Is this  book for the beginner?  The title suggests not, not
  238.      like "QuickC Programming for the IBM"  does.    But  the  authors
  239.      have  attempted  to  create  the  seeds  of excellent programmers
  240.      early in the process, instead of just gearing the  book  to  more
  241.      advanced users.   They also cover in some detail the proposed new
  242.      ANSI standard for C.  In one of the appendices  included  in  the
  243.      book, syntax  of ANSI C is outlined.  While in a later appendice,
  244.      the differences between K&R C and ANSI  C  are  outlined.    This
  245.      sort  of  detail can only add more substance and reason for me to
  246.      break my budget and purchase a copy.   I  highly  recommend  that
  247.  
  248.                                                                     Page  5
  249.  
  250.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  251.  
  252.      you do the same.
  253.  
  254.      **** Editor's Note:  This book will be used extensively in the
  255.           series on Product design that starts with this issue.  BL
  256.  
  257.                                                                     Page  6
  258.  
  259.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  260.      =====================================================================
  261.      MAGAZINE REVIEW: By barry Lynch
  262.      =====================================================================
  263.  
  264.      Magazine: Circuit Cellar Ink
  265.      Issue: Vol 1, No. 5
  266.      Publisher: Circuit Cellar Incorporated
  267.                 4 Park Street
  268.                 Suite 20
  269.                 Vernon, CT 06066
  270.                 (203)875-2751
  271.  
  272.            At this  time my favorite journal is "Micro Cornucopia".  I
  273.      also favor "C Users Journal" and the "Harvard  Business  Review".
  274.      Each  month  without  fail  each  of  these publications is read,
  275.      re-read and cataloged away for future reference.   Today,  a  new
  276.      journal threatened  to  join  that  select group:  Circuit Cellar
  277.      Ink.
  278.  
  279.           For those of us that remember Byte back when, Steve  Ciarcia
  280.      was always  one  of  the  shining  points  of  each issue.  I can
  281.      remember back in the early 80's, drooling over  a  computer  that
  282.      Mr.  Ciarcia had put together, and hoping that some day one would
  283.      find it's way to my door. (This was right before the IBM  Pc  was
  284.      introduced  I  believe)  Being  very  interested  in Software and
  285.      Hardware I find his columns  to  be  of  great  interest,  as  he
  286.      dreams up  new  wonderful  electronic  gizmos  to build.  Sort of
  287.      reminds me of  those  wonderful  hacker  days,  before  the  word
  288.      became a mark of distrust, instead of pride.
  289.  
  290.           This   magazine  is  Mr.  Ciarcia's  attempt  to  provide  a
  291.      technical journal that caters to the tinkers, and  thinkers  that
  292.      exist in  today's  computer society.  I for one am not interested
  293.      in how to program  a  Lotus  spreadsheet,  but  creating  a  Home
  294.      control  system  via  a power line interface is more my speed. In
  295.      the issue that I read today, the lead article was  on  a  project
  296.      called  "ROVER"  which  stands for "remotely operated video-based
  297.      electronic reconnaissance".  Imagine calling a  video  camera  at
  298.      home, and watching  it pan your yard at your control!!  NEAT.  If
  299.      these are the sort of articles that you like,  then  this  little
  300.      known journal  is  for you.  It is rather new and hard to find on
  301.      newsstands, but I found my copy  in  a  B.  Dalton  Software  Etc
  302.      store.   If  you  cannot  find  it  locally, consider calling the
  303.      publisher to see where it is located locally.
  304.  
  305.                                                                      Page  7
  306.  
  307.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  308.      =====================================================================
  309.      COMMENTARY: File Compression Utilities by Barry Lynch
  310.      =====================================================================
  311.  
  312.            In the Bulletin Board community,  there  is  one  group  of
  313.      utilities  that  are  as indispensable as the modems that the BBS
  314.      Systems use:  the File  compression  utilities.    Two  companies
  315.      have  been  the  leaders  in  the use of these type of utilities:
  316.      SEA Associates and Phil Katz Ware.  Both of these companies  have
  317.      been  involved  in a legal dispute over the origin of Phil Katz's
  318.      code.  Needless, to say, due to the fact that  almost  every  DOS
  319.      based  BBS system uses either ARC or PKARC, this legal action has
  320.      been followed with close scrutiny by most  system  operators  and
  321.      users alike.
  322.  
  323.           This  commentary  is  not on what package to use, but what I
  324.      have chosen to do here at the C BBS and with C  News.    Starting
  325.      with  this  issue  of  C  News, each issue will be compressed and
  326.      contained within a library using ZOO.   ZOO  is  another  of  the
  327.      File  Compression  utilities  that is currently available, to the
  328.      sysop and  user.    It  is  Public  Domain,   except   for   it's
  329.      restriction  on  pay  per  hour  BBS systems, and the C source is
  330.      available.  Here at the C BBS the latest  version  can  be  found
  331.      along  with  utilities to make the transition from ARC type files
  332.      to ZOO.
  333.  
  334.           Why did I decide to go with  ZOO?    Basically  because  the
  335.      entire SEA  vs  Pkware made me ill.  I have absolutely no problem
  336.      with making a profit off of a product which you create.  But  the
  337.      lawsuit  that  ensued  and the bickering that went back and forth
  338.      between both parties, just made me change to a librarian  utility
  339.      that was  not  under  so much heat.  Zoo is public domain as is C
  340.      News and it fit.  Simple, and  effective,  the  "ARC"  wars  have
  341.      just  begun  I  am afraid, and what you will see now is a rash of
  342.      programs  that  are  based  upon   the   essentially   the   same
  343.      algorithms, that  claim  to be faster, better and cheaper.  I for
  344.      one would like to see  a  NEW  data  compression  algorithm  that
  345.      makes these claims, that would be news.
  346.  
  347.           So  since  I  decided  to  use ZOO, would the file sizes the
  348.      smaller/bigger than the ARC's that I  currently  have?    Is  ZOO
  349.      faster,slower, or  the  same  speed  in compressing files?  These
  350.      are the questions that I will answer in the next paragraph.
  351.  
  352.           I  chose  to  use  three  C  source  files  in  a   separate
  353.      sub-directory as  my  test files.  I compressed them all into one
  354.      file using the following utilities:    SEA  Assoc.  ARC  versions
  355.      5.2,  and  5.32,  Phil  Katz's  PKARC,  PAK  version 1.0, and ZOO
  356.      version 2.01.  The source files listed with sizes  are  contained
  357.      in  Table  1.0,  and  the compression results are listed in Table
  358.      1.1.
  359.  
  360.                                                                     Page  8
  361.  
  362.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  363.  
  364.      Table 1.0 - Source files with sizes.
  365.  
  366.      SOURCE FILES
  367.  
  368.      Editor.c -  21983
  369.  
  370.      Menu.c   -   4150
  371.  
  372.      Window.c -   9339
  373.  
  374.  
  375.  
  376.      Table 1.1 - Results of Compression Utilities.
  377.  
  378.          Program            Compression                      Size of
  379.                             Ratio of each                    Test.Arc
  380.                             src file.
  381.  
  382.          SEA ARC 5.2        Editor.c  67%                      13052
  383.                             Menu.c    47%
  384.                             Window.c  60%
  385.  
  386.          SEA ARC 5.32       Editor.c  69%                      13052
  387.                             Menu.c    47%
  388.                             Window.c  54%
  389.  
  390.          PAK 1.0            Editor.c  69%                      12950
  391.                             Menu.c    48%
  392.                             Window.c  54%
  393.  
  394.          PKARC              Editor.c  68%                      13007
  395.                             Menu.c    48%
  396.                             Window.c  59%
  397.  
  398.          ZOO 2.01           Editor.c  68%                      13423
  399.                             Menu.c    47%
  400.                             Window.c  54%
  401.  
  402.  
  403.                                                                    Page  9
  404.  
  405.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  406.      =====================================================================
  407.      COMMENTARY: James L. Buie - TTL Inventor by Arnie Cherdak
  408.      =====================================================================
  409.  
  410.             I ran across this obituary in an old issue  (mid-1988)  of
  411.      one  of  those  electronics industry newspapers that I get at the
  412.      office.  I was browsing idly one day after a tough meeting...
  413.  
  414.      ***************************************************************
  415.  
  416.      PANORAMA CITY, Calif. -  James Buie, who invented and
  417.      patented transistor-to-transistor (TTL) logic in the early
  418.      1960s died here last week at the age of 68.
  419.  
  420.           Mr. Buie's invention, TTL, was to  become  the  most  widely
  421.      used  form  of circuit logic, and was broadly licensed throughout
  422.      the then-emerging integrated circuit industry by TRW,  for  which
  423.      the inventor worked.
  424.  
  425.           James  L.  Buie  was  born  in Hollywood, Calif. in 1920 and
  426.      educated at Hollywood High School and Los Angeles  City  College.
  427.      After  World  War  II,  where  he  rose to the rank of Lieutenant
  428.      Commander as a naval pilot, he  enrolled  at  the  University  of
  429.      Southern   California   for  a  bachelor  of  science  degree  in
  430.      electrical engineering.
  431.  
  432.           In 1954, Mr. Buie joined the Ramo-Wooldridge  Corp.,  a  TRW
  433.      predecessor   company,   where   he   was   assigned  to  Pacific
  434.      Semiconductor Co.    Along  with  inventing  TTL,  Mr.  Buie  was
  435.      involved   in   the   development   of   dielectrically  isolated
  436.      integrated  circuits,  a  single-chip  parallel   multiplier,   a
  437.      single-chip   analog-to-digital   converter  and  triple-diffused
  438.      bi-polar devices.
  439.  
  440.           Until 1977, Mr. Buie served as  technical  leader  of  TRW's
  441.      Microelectronics Center,  which  he  helped to establish.  He was
  442.      also instrumental in the startup of the  LSI  Products  Division,
  443.      where he worked until his retirement in 1983.
  444.  
  445.           Mr.  Buie  is  survived  by  his  wife, Ione, a son, John, a
  446.      daughter, Janet Reasoner,  a  sister  Joan  Runsvold,  and  three
  447.      great-grandchildren.
  448.  
  449.      ***********************************************************
  450.                                                                    Page  10
  451.  
  452.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  453.      =====================================================================
  454.      COMMENTARY: James L. Buie - TTL Inventor by Arnie Cherdak
  455.      =====================================================================
  456.  
  457.           I  was  virtually  dumbstruck  when I finished reading this.
  458.      How could this be, that the man who  invented  TTL,  one  of  the
  459.      inventions  that  made  modern  digital  electronics and computer
  460.      technology  a  practical  enterprise,  died  and   only   got   9
  461.      column-inches  in the back of a trade journal (name forgotten--my
  462.      apologies) for his remembrance.
  463.  
  464.           I never knew James Buie.  I didn't even know he did what  he
  465.      did until  I  read  his obituary.  But now I sure know who he was
  466.      and I, for one, won't  forget  his  contribution.    I  hope  his
  467.      great-grandchildren  will  know  about  and  remember him as well
  468.      because  they  can  have  pride  in   their   great-grandfather's
  469.      accomplishments as an engineer who put an industry to work.
  470.  
  471.      **********************************************************
  472.  
  473.      EDITOR'S NOTE:  I agreed to publish this article on James
  474.                      Buie because I felt it was important to
  475.                      remember the man that helped to create the
  476.                      hobby or vocation that we all enjoy. BL.
  477.  
  478.      ***********************************************************
  479.                                                                    Page  11
  480.  
  481.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  482.      =====================================================================
  483.      PROGRAM DESIGN: OpusGraf a Project:  Part I:
  484.      =====================================================================
  485.      by Barry Lynch and Jim Singleton
  486.  
  487.      Editor's Note:  This article is the first in a continuing series on
  488.                      software development.  OpusGraf is a opus log utility
  489.                      that creates a bargraph showing utilization for a given
  490.                      day.  This graph can then be output to a file to be used
  491.                      as a bulletin.  This project will be of interest to all
  492.                      users interested in graphics.
  493.  
  494.      [Introduction]
  495.  
  496.           The  idea  for  this  article came from discussion at one of
  497.      the C BBS user's meetings that  are  held  every  month  here  in
  498.      Virginia.   The  idea  of an article that discussed the evolution
  499.      of a software project, was one that quite a few people showed  an
  500.      interest in.    Specifically, Jerry Zeisler in Issue 12 of C News
  501.      made some interesting observations in his first attempt  at  a  C
  502.      application.
  503.  
  504.            Those  observations  were  the  motivation that I needed to
  505.      sit down and create this project.  The other motivation was  that
  506.      when  I  ran  a  PC  Board  Bulletin  Board System, a utility was
  507.      available to  show  the  utilization  of  the  board.    And  the
  508.      bulletin  that it generated was one of the more popular bulletins
  509.      on the system.
  510.  
  511.           Therefore, this article is the first in a series  that  will
  512.      show  the  development of a utility and outline some of the right
  513.      things to do, and show some of the things that went wrong.    The
  514.      general plan for content of each article is as follows:
  515.  
  516.           Issue       Article/Subject
  517.  
  518.            13         Introduction, and Product Specification
  519.            14         Detailed Design Document and Flow of Program
  520.            15         First BETA release of OpusGraf
  521.            16         Bug reports and Corrections
  522.            17         Final Release and a Post Mortem Analysis
  523.  
  524.           This  syllabus allows me to show a complete detailed view of
  525.      the project, and provide some educational value.  I believe  that
  526.      it   will  also  prove  to  be  interesting  reader  for  Fidonet
  527.      developers and C news readers.
  528.  
  529.      SECTION I:  The IDEA!
  530.  
  531.            How often do you sit at a desk and come  up  with  an  idea
  532.      for a  program  or  great  application that we all need?  What do
  533.      you do?  Write down your thoughts then and there, or  store  them
  534.      away for  a  later  date?  I personally carry a Black Composition
  535.      book - the kind that you find in school  bookstores  -  and  make
  536.      entries as  needed.  At the end of week, I go through the entries
  537.  
  538.                                                                    Page  12
  539.  
  540.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  541.  
  542.      and make a list of the ones  that  I  want  to  work  on,  and  a
  543.      scratch  out  those that either I have no time for, or was really
  544.      banana wackers to think of.
  545.  
  546.           Once an idea has made it to the "To Do"  list,  then  it  is
  547.      time  to  think  of exactly what it is I am trying to accomplish.
  548.      This is how OpusGraf started,  a  brief  thought  that  the  OPus
  549.      sysops  needed  such  a  utility, and it would make a good C News
  550.      series.  So, what is it that I want to accomplish?   Well,  let's
  551.      see:
  552.  
  553.             - A Utility that will read the previous day's opus.log
  554.               and generate a Bar-Graph showing usage.
  555.             - The ability to redirect the Bar-Graph to a disk file
  556.               for showing as a Bulletin.
  557.             - The option for the sysop to break out the type of utilization
  558.               to be shown: i.e.: Human Caller/Mail/FR/Maintenance, or All.
  559.  
  560.      [Product Specification]
  561.  
  562.           Now  that  the  idea  is written down and a short but simple
  563.      list of objectives is written the design work  can  begin.    The
  564.      first  thing  to do is to create a rough outline of what you want
  565.      the program to do.  Listed below is a simple outline that can  be
  566.      used as a guideline:
  567.  
  568.            - Abstract of project
  569.            - Command line interface
  570.            - Input file syntax
  571.            - Screen design
  572.            - Output file format descriptions
  573.            - Interactive command language (If needed)
  574.            - Error messages
  575.            - Future extensions
  576.  
  577.           Now  for  a sample product specification for OpusGraf, based
  578.      upon the outline listed above.
  579.  
  580.      1.  Abstract
  581.  
  582.          The intent of this project is to create an Fidonet Compatiable
  583.          graphic utilization utility.  It will support:
  584.  
  585.          o  Opus BBS systems
  586.          o  Fido BBS systems
  587.  
  588.          The goal of this project is to show some principles of software
  589.          engineering and project management while creating a useful Fidonet
  590.          based Utility.
  591.  
  592.      2.  Command Line Interface
  593.  
  594.          The command line does not need to include any parameters, unless the
  595.          user would like to overide some values that exist in the configuration
  596.          file.  Valid command line parameters are:
  597.  
  598.                                                                    Page  13
  599.  
  600.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  601.  
  602.               -A                Tells Opusgraf to use all categories of util-
  603.                                 ization, i.e.: Human Caller/Machine etc.
  604.  
  605.               -F<Path:filename> Path and filename of the configuration file
  606.                                 if not the default Opus/Fido/Opusgraf
  607.                                 directory.
  608.  
  609.               -S                Direct output to screen only, no output file
  610.                                 is created.
  611.  
  612.      3.  Input file syntax
  613.  
  614.          File #1: Opus.log
  615.  
  616.          The input file will be the Opus.log file created by the OPus BBS
  617.          system.  <I will look for a technical description fof the format
  618.          in the FTSC documents that outline the technical details of Fido
  619.          net.>
  620.  
  621.          File #2: opusgraf.cfg
  622.  
  623.          This is the Opusgraf configuration file that contains certain para-
  624.          meters needed by the Opusgraf program.  The layout is the same that
  625.          is used by other OPus/Fido utilities, for ease of familiarity and
  626.          use by the end user.
  627.  
  628.          ;***************************************************************
  629.          ;*
  630.          ;* OpusGraf Ver 1.0 Configuration file
  631.          ;*
  632.          ;* Written by B. Lynch and J. Singleton of the C BBS 109/713
  633.          ;*
  634.          ;* Purpose:  This file is used by Opusgraf.exe to determine what
  635.          ;*           the default operating parameters are.
  636.          ;*
  637.          ;* Created for an article in C News Issue's 13-17 (12/88-5/89)
  638.          ;*
  639.          ;*
  640.          LOG c:\opus\opus.log   /* The actual opus or fido log to be used */
  641.          ALL       /* accumulate all utilization into hourly calculations */
  642.          ;NOTALL  /* break out the different utilizations by hr by % */
  643.          BOARD The C BBS  /* Your board name */
  644.          SYSOP Barry Lynch  /* Your name */
  645.          ;LOGO  "The Home of C BBS"   /* Logo or motto of your board */
  646.          ;
  647.  
  648.      4.  Interactive Command Language
  649.  
  650.           Not needed in this application.
  651.  
  652.      5.  Error Messages
  653.  
  654.          The Opusgraf program supports the following error codes:
  655.  
  656.          1 - No OpusGraf.cfg file found
  657.          2 - Log file not found - as specified by config file
  658.          3 - Not enough memory to run utility
  659.  
  660.                                                                    Page  14
  661.  
  662.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  663.  
  664.          4 - Unable to write out disk file - Not enough Free disk space
  665.          5 - Incorrect command line values <show help screen>
  666.  
  667.           Once you have completed the rudimentary design, a detailed design
  668.      document is needed to outline the algorthims used, libraries, compiler
  669.      etc.  We will save that document for the next issue of C News.
  670.  
  671.                                                                    Page  15
  672.  
  673.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  674.      =====================================================================
  675.      An Introduction to AWK by Dan Kozak
  676.      =====================================================================
  677.  
  678.      Why AWK?
  679.  
  680.              Every programmer spends more time than  they  will  admit
  681.      doing rather  mundane  tasks.  First you hear a rhythmic clicking
  682.      from their keyboard,  going  faster  than  any  programmer  could
  683.      possibly type  unless it was a totally repetitive job.  "What are
  684.      you doing?" "Ummm, well I found a much  better  way  to  lay  out
  685.      these  data  files, but I have to go in and indent like so, put a
  686.      tab here and two newlines as a delimiter and then .  .  ."  Sound
  687.      familiar?
  688.  
  689.          You   find  yourself  doing  all  kinds  of  data  formatting
  690.      manually that you should really get the computer to  do  for  you
  691.      because  it's  just  too  much bother to write a program to do it
  692.      and anyway, you only have to do it once (sure).    AWK  is  great
  693.      for  quick  data  transformations,  validations, reports and also
  694.      for prototyping larger programs. You may find  that  knowing  AWK
  695.      will  make  jobs  like  this  so simple that the equation tips in
  696.      favor of ACTUALLY WRITING A  PROGRAM  TO  DO  THE  JOB  FOR  YOU!
  697.      (Remember:  computers are supposed to make life easier.)
  698.  
  699.      [What is AWK?]
  700.  
  701.          AWK   is   an  interpretive  programming  language  that  was
  702.      developed by Alfred Aho, Peter  Weinberger  and  Brian  Kernighan
  703.      (put  the  first  letters of their last names together . . . ) at
  704.      Bell Labs.
  705.  
  706.          Although  originally  designed  for   short,   one-time   use
  707.      programs,  it  has  been  extended  to  handle more complex jobs,
  708.      making it  more  of  a  complete  language.    Because   of   its
  709.      interpretive  nature  and the way some of its constructs work, it
  710.      is not  especially  fast,  but  when  development  time  is  more
  711.      important  than  run-time (i.e. you don't use the program all the
  712.      time)  and  the  amount  of   data   isn't   overwhelming   AWK's
  713.      performance is  fine.    Although  it's  origin as a UNIX tool is
  714.      shown in it's use of regular expressions and a C-like syntax,  it
  715.      is applicable  to other operating systems as well;  in particular
  716.      there are implementations under MS-DOS (without which I  wouldn't
  717.      be writing this).
  718.  
  719.      [How does AWK work?]
  720.  
  721.          In  AWK,  much  of  the work of writing a program is done for
  722.      you by the structure of the language.  Each program  consists  of
  723.      a  series  of patterns and actions, the input file(s) are read in
  724.      and every time a pattern is matched the corresponding actions  is
  725.      taken.  An  AWK  program is an implicit loop that, in pseudo code
  726.      looks like this:
  727.  
  728.              (optionally do something here before we start)
  729.              while (not end of input file(s) )
  730.  
  731.                                                                    Page  16
  732.  
  733.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  734.  
  735.               if (there is a pattern match)
  736.                take the coresponding action
  737.              (optionally do something here when we're done)
  738.  
  739.      [What are patterns?]
  740.  
  741.          A pattern is a way of specifying "this line of input  belongs
  742.      in set  A and that line does not".  When you apply a pattern to a
  743.      line of input the result is a  logical  value  (TRUE/FALSE)  that
  744.      determines whether the coresponding action should be taken.
  745.  
  746.          One  kind  of  pattern  is the regular expression, a notation
  747.      for describing a pattern to match that is  used  throughout  UNIX
  748.      (MS-DOS users:    "wildcarding"  of  filenames  is  a  very small
  749.      subset of UNIX regular expressions).   A  regular  expression  is
  750.      usually  delimited  by  slashes  ("/")  and  specifys, using both
  751.      normal characters and "meta-characters" a pattern  to  look  for.
  752.      So a simple AWK program might look like this:
  753.  
  754.      /UNIX/  { print }
  755.        ^         ^
  756.        |         +--action
  757.      pattern
  758.  
  759.           This  would  print every line in the input file that had the
  760.      pattern "UNIX" in it.  Actually the default action (we'll get  to
  761.      those  soon)  is  print  so  this example could be written at the
  762.      command line level like this:
  763.  
  764.      awk "/UNIX/" input.fil
  765.  
  766.      (for the rest of this article, though, I will  continue  put  the
  767.      superfluous  {  print  }  because it reads clearer.) The default,
  768.      outer level pattern is "match all lines" so this:
  769.  
  770.      { print }
  771.  
  772.      would simply print all lines.   Patterns  can  be  compound  like
  773.      this:
  774.  
  775.      /UNIX|AWK/ { print }               # the | symbol is a logical OR
  776.  
  777.          The  complete  syntax  of regular expressions is more than we
  778.      can go into here, but there  is  ample  UNIX  literature  on  the
  779.      subject.
  780.  
  781.          Patterns  don't  have  to be regular expressions, they can be
  782.      any kind  of  expression.    AWK  automatically  performs   field
  783.      splitting  on  the  input  lines (the default delimiter is "white
  784.      space" [space, tab, newline] but  can  be  changed).    NF  is  a
  785.      built-in  AWK  variable that is the number of fields in the input
  786.      line. This AWK program:
  787.  
  788.      NF < 10 { print }
  789.  
  790.      will print all input lines that have less that 10 fields.   Field
  791.      splitting  also  gives  you  access to the indivdual fields in an
  792.      input line via the  $0,  $1,  $2,  .  .  .,  $n  variables.    $0
  793.  
  794.                                                                    Page  17
  795.  
  796.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  797.  
  798.      represents  the  entire input line, while $1 represents the first
  799.      field, $2 the second, and so on.  As an example:
  800.  
  801.      $1 == "AWK" { print }
  802.  
  803.      would print all lines whose first field is  the  word  AWK.    Of
  804.      course  more  complex  patterns  can be fashioned using the AWK's
  805.      logical operators ||, &&,  and so on  (these  perform  the  same
  806.      functions they do in C).
  807.  
  808.      [What are actions?]
  809.  
  810.          Actions  are the part of AWK that most closely resemble other
  811.      programming languages, in  particular  C.    Actions  consist  of
  812.      function calls,  assignments  and  conditionals.    We've already
  813.      seen the print function  at  work,  but  let's  look  at  another
  814.      output function, one that should be familiar to C programmers.
  815.  
  816.      { printf("%3d:  %s\n",NR, $0) }
  817.  
  818.      (the  built-in  variable  NR  is the number of records read) This
  819.      example would print the input file with every  line  preceded  by
  820.      its line  number.    Assignments  also  work  like C, except that
  821.      variables need not be declared and have an initial numeric  value
  822.      of  0  and  an  initial  string  value  of "" (the empty string).
  823.      Here's a quick word count program:
  824.  
  825.      {
  826.        words += NF
  827.        chars += length($0) + 2             # DOS uses a CR-LF combination
  828.      }
  829.      END  { print "Characters:",chars,"Words:",words,"Lines:",NR }
  830.  
  831.           Here  we've  introduced  variables (except for the fact that
  832.      all  variables  in  AWK  have  both  a  string  and   a   numeric
  833.      representation  that  are  used according to context, there's not
  834.      much say about  these,  you  just  use  them),  assignments,  the
  835.      length  function (one of several built-in functions), the comment
  836.      character (#) and the END pattern.  The BEGIN  and  END  patterns
  837.      are  matched  when  the program starts, before any input has been
  838.      read and after all input has been read, respectively.
  839.  
  840.           By making assignments to the field variables ($1, $2 . .
  841.      .), you can replace or create those fields:
  842.  
  843.      { $(NF+1) = "!EOL!"
  844.        print
  845.      }
  846.  
  847.      This program adds the string "!EOL!" the end of  every  line  and
  848.      then prints it.
  849.  
  850.          Just  to  give  you a feel for the kind of things actions can
  851.      do, AWK provides 14 built-in variables  (we've  seen  NF  and  NR
  852.      already)  that  give  access  to  the command line arguments, the
  853.      filename  of  the  current  input  file,  the  field  and  record
  854.      separators  for  input  and  output  and  the  default format for
  855.      numbers, 9 built-in math functions including random  numbers,  12
  856.      built-in  string  functions  (we've used length()) that provide a
  857.      
  858.                                                                    Page  18
  859.  
  860.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  861.  
  862.      variety of search and replace functions and all the control  flow
  863.      statements  that  exist  in  C  (if,  while,  for do . . . while,
  864.      break, continue) except for switch.   While  space  prohibits  us
  865.      from  looking at all of these, you should be able to see that AWK
  866.      provides a wide range of tools.
  867.  
  868.      [Associative Arrays]
  869.  
  870.          The way AWK handles arrays is different enough to  merit  its
  871.      own discussion.    Arrays  in  AWK  are one dimensional (although
  872.      there is a feature to simulate two dimensional arrays,  we  won't
  873.      go  into  that here), can hold numbers or strings and need not be
  874.      declared.  However, AWK arrays are subscripted by strings not  by
  875.      integers  (this  gives them some of the capabilities of SNOBOL4's
  876.      "associative memory" and that's why they are  called  associative
  877.      arrays).   The  best  way  to  understand this is an example from
  878.      "The AWK Programming Language":
  879.  
  880.      /Asia/     { pop["Asia"] += $3 }
  881.      /Europe/   {  pop["Europe"]  +=  $3  }
  882.      END        { print "Asian population is", pop["Asia"], "million."
  883.           print "European populations is",pop["Europe"],
  884.                   "million"
  885.                  }
  886.  
  887.      When  provided  with test data containing a country, it's area in
  888.      thousands of square miles, it's population in  millions  and  the
  889.      continent it is in formatted like this:
  890.  
  891.      USSR     8649   275   Asia
  892.      Canada   3852   25       North America
  893.      China    3705   1032  Asia
  894.      USA      3615   237   North America
  895.      Brazil   3286   134   South  America
  896.      India    1267   746   Asia
  897.      Mexico   762    78    North America
  898.      France   211    55       Europe
  899.      Japan    144    120   Asia
  900.      Germany  96     61    Europe
  901.      England  94     56       Europe
  902.  
  903.      this program produces the output:
  904.  
  905.      Asian population  is  2173  million. 
  906.      European populations is 172  million
  907.  
  908.           There are also some special constructs for use  with  arrays
  909.      like  the  "in"  operator, used to determine whether a particular
  910.      subscript exists in an array, "for (var  in  array)"  which  will
  911.      loop  through  all the subscripts in an array, "delete" to remove
  912.      an element from an array and "split()", to  divide  a  string  up
  913.      and place  it's  fields  in  an  array.    Array  operations  are
  914.      powerful in AWK, but sometimes hard to understand,  so  refer  to
  915.      "The  AWK Programming Language" for the details (something you'll
  916.      probably have to do more than once :-).
  917.  
  918.                                                                    Page  19
  919.  
  920.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  921.  
  922.  
  923.      [Just the tip of the iceberg!]
  924.  
  925.          There's more to AWK than I could go into here:  user  defined
  926.      functions,  more  complex  output  statements, reading from files
  927.      other than those specifed as input (allows you to interleave  two
  928.      files  to  produce a report, for example), calls to the operating
  929.      system through  the  system()  function  (works  like  C),  among
  930.      others. But, you can . . .
  931.  
  932.      [Do it yourself]
  933.  
  934.          Getting started  with  AWK  is  easy.    There  is a freeware
  935.      version by Rob Duff that is available with source  from  his  BBS
  936.      (604-251-1816)   which  was  used  in  the  preparation  of  this
  937.      article.  Try the programs in the  article  (the  article  itself
  938.      makes a good test input file) to see how you like it.
  939.  
  940.          If  you  want to go further, the required reading is "The AWK
  941.      Programming  Language"  by   Aho,   Kernighan   and   Weinberger,
  942.      Addison-Wesley,  ISBN  #0-201-7981-X which serves as a manual and
  943.      tutorial for the language.  There  are  also  several  commercial
  944.      DOS  implementations  of AWK, most notably Mortice Kerns Systems'
  945.      and Polytron's PolyAWK.
  946.  
  947.      [An example]
  948.  
  949.          In closing I leave you  with  an  example  I  whipped  up  in
  950.      response to  a  question  on  the  FidoNet  C echo.  This program
  951.      counts the lines of code in C program(s) excluding comments.   It
  952.      reports  the  total number of lines in each file and all together
  953.      with and without preprocessor directives.  The FILENAME built  in
  954.      variable  is  the name of the current input file and the ~ and !~ 
  955.      operators  are  the  "match"  and  "no   match"   operators   for
  956.      specifying regular  expressions  within  a  program.  The regular
  957.      expressions here are rather dense because C's  comment  delimiter
  958.      "/*  .  .  .  */"  shares a character with AWK regular expression
  959.      delimiter "/",  so  every  occurence  of  "/"  within  a  regular
  960.      expression must be quoted with the "\" character.  But even  with
  961.      that complication, this program was up and running in about 20
  962.      minutes.
  963.  
  964.                                                                    Page  20
  965.  
  966.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  967.  
  968.    
  969.      # count lines in a C program, not counting comments or form feeds
  970.      # does separate count of preprocessor directives
  971.      # if a preprocessor directive is commented out, it does not count
  972.      {
  973.       if (file == "") file = FILENAME
  974.       if (file != FILENAME) {
  975.        printf("Number of lines in %s is: %d\n",file,nl+ppd)
  976.        printf("Number of preprocessor directives is: %d\n",ppd)
  977.        printf("Number of lines excluding preprocessor directives is: \
  978.         %d\n\n",nl)
  979.        file = FILENAME
  980.        tnl += nl
  981.        tppd += ppd
  982.        nl = 0
  983.        ppd = 0
  984.       }
  985.  
  986.       # don't count blank lines
  987.       if ($0 == "") { ; }                   
  988.       # don't count lines that are all comment
  989.       else if ($1 ~ /^\/\*/ && $NF ~ /\*\/$/) { ; } 
  990.       # flag beginning of multi-line comment
  991.       else if ($0 ~ /\/\*/ && $0 !~ /\*\//) { in_comment = 1 }
  992.       # flag end of multi-line comment
  993.       else if ($0 !~ /\/\*/ && $0 ~ /\*\//) { in_comment = 0 }
  994.       # don't count while in comment
  995.       else if (in_comment) { ; }
  996.       # count preprocessor directives separately
  997.       else if ($1 ~ /^#/) { ppd++ }
  998.       # count everything else
  999.       else nl++
  1000.       }
  1001.  
  1002.       END { printf("Number of lines in %s is: %d\n",file,nl+ppd)
  1003.       printf("Number of preprocessor directives is: %d\n",ppd)
  1004.       printf("Number of lines excluding preprocessor directives is: %d\n\n",nl)
  1005.       file = FILENAME
  1006.       tnl += nl
  1007.       tppd += ppd
  1008.       printf("Total number of lines is: %d\n",tnl+tppd)
  1009.       printf("Number of preprocessor directives is: %d\n",tppd)
  1010.       printf("Number of lines excluding preprocessor directives is: %d\n",tnl)
  1011.     }
  1012.                                                                   Page  21
  1013.  
  1014.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1015.      =====================================================================
  1016.      CHANGING A FILE ATTRIBUTE IN C: by Chris Kryza
  1017.      =====================================================================
  1018.  
  1019.      ABSTRACT:  Back in early November, Chris wanted to  know  how  to
  1020.      change a  files  attribute in DOS.  Two solutions were presented:
  1021.      1) use the ATTRIB command, and the 2) Use the _chmod function  in
  1022.      TurboC.   This  article  outlines  a  program that Chris wrote to
  1023.      accomplish the latter.
  1024.  
  1025.      INTRODUCTION
  1026.  
  1027.      From:  Chris Kryza Rec'd
  1028.      To:    Bill  Mayne      Msg  #44,  04-Nov-88      08:16EST
  1029.      Subject:  Archive Bit
  1030.  
  1031.      Bill, thanks  for  you  info re the attrib command.  It is one of
  1032.      those DOS commands that I long ago forgot about.  After  doing  a
  1033.      little  research, I found a way to accomplish the same thing from
  1034.      within a Turbo C program using the  _chmod  function  defined  in
  1035.      io.h.  This  func  takes three arguments:  filename (char *), get
  1036.      or set flag (int 0 or 1), and mask (to set archive  bit:    0x20,
  1037.      to clear  same  0x00).   You can also set or clear all other file
  1038.      attributes via this function,  i.e.  hidden  file,  system  file,
  1039.      read-only, etc.  Thanks for putting me on the right track!
  1040.  
  1041.                                             CDK.
  1042.  
  1043.      *** There is a reply. See #51.
  1044.  
  1045.  
  1046.      From:  Bill  Mayne  Rec'd
  1047.      To:    Chris  Kryza                   Msg #51, 06-Nov-88 18:12EST
  1048.      Subject:  Re:  Archive Bit
  1049.  
  1050.      Glad you solved your problem  with  the  archive  bit.  Obviously
  1051.      both  the  attrib command and the function you mentioned are just
  1052.      different ways to call the same  DOS  interrupt.  It  is  amazing
  1053.      that  MS  doesn't  provide  commands  to  use  some  other useful
  1054.      interrupts, like renaming a  file  into  a  different  directory.
  1055.      Fortunately  almost  all  C  compilers  provide  a  fairly simple
  1056.      function to call any interrupt you want, though it is nice as  in
  1057.      this  case  to have a more specific function for what you want so
  1058.      you don't have to worry about the registers yourself.
  1059.  
  1060.      *** This is a reply to #44.
  1061.  
  1062.                                                                    Page  22
  1063.  
  1064.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1065.      =====================================================================
  1066.      Interactive C Graphics using TurboC  by  Scott  Houck.    Part  I
  1067.      =====================================================================
  1068.  
  1069.            I  recently  completed  a  college  course  in  interactive
  1070.      computer graphics.    Most  of  the  students  were  doing  their
  1071.      projects on  Macintosh  computers.  Since I have an AT clone with
  1072.      an EGA at home, I got permission to use my home computer  for  my
  1073.      projects.
  1074.  
  1075.            I  had  just  gotten  Turbo  C  2.0,  so  this  was  a good
  1076.      opportunity to acquaint myself  with  Turbo's  graphics  package.
  1077.      In  this  installment  of  C  News,  I  will  present  some basic
  1078.      graphics concepts and show  how  to  use  Turbo  C  to  implement
  1079.      simple geometric  transformations.   The programs require a mouse
  1080.      and either an EGA or VGA graphics adapter.
  1081.  
  1082.           I am writing this article not as a  graphics  or  C  expert,
  1083.      but  as  an  intermediate  C  programmer  who  is  learning about
  1084.      graphics and in particular, Turbo C's graphics  package.    There
  1085.      are  no  doubt  many  insights  that  others could provide, and I
  1086.      welcome any comments or advice.
  1087.  
  1088.      [MOUSE PROGRAMMING]
  1089.       -----------------
  1090.  
  1091.            I have a Microsoft mouse, and I used  the  Microsoft  Mouse
  1092.      programming guide  for  information  on programming the mouse.  I
  1093.      have not looked into other types of mice, but I do know  that  my
  1094.      program does  not  work  correctly  with  the  Logitech mouse.  I
  1095.      assume the Logitech mouse must be programmed differently.
  1096.  
  1097.            The Microsoft mouse uses interrupt 33h.  Each  function  is
  1098.      numbered  and  specified by placing the function number in the AX
  1099.      register.   Other  registers  are  used   to   specify   function
  1100.      parameters, if  any.  I used the int86() function to interface to
  1101.      the CPU registers.  I experimented with Turbo's pseudo  variables
  1102.      before  using  int86(),  but  got  some surprising results in the
  1103.      MouseStatus() function since registers containing  return  values
  1104.      were being  overwritten  before  the  function returned.  Be very
  1105.      careful with pseudo variables!  I could not figure out  what  was
  1106.      happening until I generated an assembly language listing.
  1107.  
  1108.           All  mouse  functions in the program begin with "Mouse" as a
  1109.      prefix.  Here is a summary of the mouse functions I created:
  1110.  
  1111.      MouseReset -- Resets the mouse to its defaults, tells you whether
  1112.      the mouse hardware and software are installed or not, and also
  1113.      returns the number of buttons in the mouse
  1114.  
  1115.      MouseOn -- Shows the mouse cursor
  1116.  
  1117.      MouseOff -- Hides the mouse cursor
  1118.  
  1119.      MouseStatus -- Returns the state of the left and right buttons
  1120.      and the horizontal and vertical coordinates of the cursor
  1121.  
  1122.                                                                    Page  23
  1123.  
  1124.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1125.  
  1126.      MouseWaitForPress -- A high level routine that loops until
  1127.      the user presses a button
  1128.  
  1129.      MouseWaitForRelease -- A high level routine that loops until the
  1130.      user releases a button
  1131.  
  1132.      MouseSetHorizPos -- Sets the minimum and maximum horizontal
  1133.      cursor coordinates on the screen
  1134.  
  1135.      MouseSetVertPos -- Sets the minimum and maximum vertical cursor
  1136.      coordinates on the screen
  1137.  
  1138.      MouseRestrict -- A high level routine that restricts the cursor
  1139.      to the viewport
  1140.  
  1141.      MouseFree -- A high level routine that frees the cursor to move
  1142.      about the entire screen
  1143.  
  1144.  
  1145.      [DEFINITION OF THE PROJECT]
  1146.       -------------------------
  1147.  
  1148.            The program I am presenting allows you  to  manipulate  two
  1149.      types of  objects  (a  triangle and a square) on the screen.  You
  1150.      can create an object, delete an object, move  an  object,  delete
  1151.      all  objects,  print the objects' data structure in a file called
  1152.      PROJ1.DAT,  cancel  an  operation,  and  quit  the  program.  The
  1153.      objects are  placed  in a room.  The "room" is square, 15 feet on
  1154.      each side.  The  square  is  one  foot  on  each  side,  and  the
  1155.      triangle is also one foot on each side.
  1156.  
  1157.      [SOME BASIC GRAPHICS THEORY]
  1158.       --------------------------
  1159.  
  1160.           This  program  demonstrates  basic geometric transformations
  1161.      -- translation,  scaling,  and  rotation.    To  understand   the
  1162.      program, some  knowledge  of  graphics  theory is needed.  I will
  1163.      not give exhaustive explanations here, but a general overview  is
  1164.      in order.    Matrices  are  used in the program, so it is assumed
  1165.      that  the  reader  has   some   familiarity   with   manipulating
  1166.      matrices.
  1167.  
  1168.           The  "room"  is  a  "window"  from  the  "world" that we are
  1169.      trying to display on the screen.  The room is square, 15 feet  on
  1170.      each side.   Those  are its world coordinates.  The term "window"
  1171.      has taken on several different  meanings  over  the  years.    In
  1172.      standard  graphics  terminology, however, a "window" is a usually
  1173.      rectangular area that is a subset  of  your  "world".    In  this
  1174.      case,  the  window  is  the  15  foot  square  area  in our world
  1175.      coordinate system.  We must transform the window to  an  area  on
  1176.      the  graphics screen -- either the entire screen or a rectangular
  1177.      area of the screen.   This  screen  area  is  referred  to  as  a
  1178.      viewport.
  1179.  
  1180.            When  we  manipulate  objects  on  screen, we must take the
  1181.      mouse coordinates (physical  device  coordinates  --  640x350  on
  1182.      EGA,  640x480  on VGA) and transform them into world coordinates.
  1183.      All changes to  data  about  the  objects  are  stored  in  world
  1184.  
  1185.                                                                    Page  24
  1186.  
  1187.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1188.  
  1189.      coordinates, which   are   floating   point   numbers.     Screen
  1190.      coordinates are always integers.
  1191.  
  1192.      [TRANSLATION]
  1193.       -----------
  1194.  
  1195.           One of the basic graphics operations  is  translation,  that
  1196.      is, moving  an object.  To translate a point with coordinates (x,
  1197.      y) by an amount Dx in the x direction and Dy in the y  direction,
  1198.      add the  translation  amount  to  each coordinate:  (x+Dx, y+Dy).
  1199.      In matrix notation, if p = [x y], p' = [x' y'], and T = [Dx  Dy],
  1200.      then p'  =  p + T.  When translating an object, each point of the
  1201.      object must be translated.  For the  triangle  and  square,  each
  1202.      vertex  will  be  translated  and the object will be redrawn from
  1203.      the translated vertices.
  1204.  
  1205.      [SCALING]
  1206.       -------
  1207.  
  1208.           Scaling means to change the size of an object.   Scaling  is
  1209.      done in  the  x  direction and the y direction.  The scale factor
  1210.      does not need to be the same for both  directions.    Scaling  is
  1211.      always done  about  the  origin  of  the  coordinate system.  For
  1212.      example, if you are reducing an object, not only will  the  lines
  1213.      become smaller, but they will get closer to the origin.
  1214.  
  1215.           Which brings  us to snag #1.  All this neat theory I learned
  1216.      in graphics class was  for  a  coordinate  system  in  which  the
  1217.      origin  (0,  0)  is  located  in  the  bottom  left corner of the
  1218.      screen.  However, PC graphics always seem to place the origin  in
  1219.      the  upper  left  corner  of the screen, so I often had to adjust
  1220.      formulas to work with the PC.
  1221.  
  1222.           To scale a point, multiply the x  coordinate  by  the  scale
  1223.      factor  for  the  x  direction, and the y coordinate by the scale
  1224.      factor for the y direction:  x' = x * Sx,  y'  =  y  *  Sy.    In
  1225.      matrix notation, if p = [x y] and
  1226.  
  1227.          | Sx   0 |
  1228.      S = | 0   Sy |, then p' = p * S.
  1229.  
  1230.      [ROTATION]
  1231.       --------
  1232.  
  1233.           To  rotate  a  point about the origin by an angle theta, the
  1234.      formulas are:  x' = x * cos(theta) - y * sin(theta), and y'  =  x
  1235.      * sin(theta) + y * cos(theta).  In matrix notation, if p = [x y]
  1236.  
  1237.              |   cos(theta)  sin(theta)  |
  1238.      and R = |  -sin(theta)  cos(theta)  |, then p' = p * R.
  1239.  
  1240.           Rotation is  always  about  the origin.  To get an object to
  1241.      rotate about its center, you must translate  the  center  to  the
  1242.      origin,   rotate,   then   translate  it  back  to  its  original
  1243.      position.  If you do not  translate  the  object  to  the  origin
  1244.      first,  the  object  will  rotate as if travelling along a circle
  1245.      with its center at the origin.
  1246.  
  1247.                                                                    Page  25
  1248.  
  1249.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1250.  
  1251.      [HOMOGENEOUS COORDINATES]
  1252.       -----------------------
  1253.  
  1254.           Matrices are nice to work with  in  calculations,  but  they
  1255.      are  even  more  convenient  if  the  coordinates are homogeneous
  1256.      (expressed similarly).  Then matrices may be combined to  express
  1257.      composition.   For  example,  a translation followed by a scaling
  1258.      followed by another translation can be done  by  multiplying  the
  1259.      respective  matrices  together  and  applying  the product to the
  1260.      point in question.
  1261.  
  1262.           Two-dimensional homogeneous coordinates are expressed as  3D
  1263.      matrices,  where the last dimension is usually 1 (thought of as a
  1264.      plane parallel to the x-y axis, the w=1 plane).  So p(x,  y,  w),
  1265.      w<>0, is the  point  in 3D.  The 2D projection is (x/w, y/w).  If
  1266.      w=1, there is no need to divide, so the  2D  point  is  just  the
  1267.      first two  coordinates.    Again,  I  will  not  go into any more
  1268.      theory on this, but there is more explanation in the comments  of
  1269.      the code.      See   the  functions  Translate(),  Rotate(),  and
  1270.      CalcW2Vmatrix() for more explanation.  By  the  way,  calculating
  1271.      the window  to  viewport  matrix  brings us to snag #2:  when you
  1272.      use Turbo C's setviewport() function, the upper  lefthand  corner
  1273.      is  changed  from  its  normal  screen  coordinates  to a logical
  1274.      coordinate of (0, 0).  While  I  am  sure  this  simplifies  many
  1275.      types  of  operations,  it  changes  these  matrix calculations a
  1276.      bit.
  1277.  
  1278.      [OPERATION OF THE PROGRAM]
  1279.       ------------------------
  1280.  
  1281.           The user must first place at least one object in  the  room.
  1282.      This  is  done  by choosing the CREATE button with the left mouse
  1283.      button, then clicking on the  triangle  or  square,  and  finally
  1284.      choosing  a  location  in  the  room  and clicking with the mouse
  1285.      button to place the object.    Deleting  an  object  is  done  by
  1286.      choosing  DELETE,  then  clicking on the object in the room to be
  1287.      deleted.  MOVE is done by clicking on MOVE, then  "dragging"  the
  1288.      object  with  the  left  button  depressed,  then  releasing  the
  1289.      button.  Rotating is performed by choosing ROTATE, then  clicking
  1290.      on  an object to be rotated, then clicking or holding down either
  1291.      the  left  or   right   button   (rotates   counterclockwise   or
  1292.      clockwise), then  choosing  QUIT  when done.  DELETE ALL asks for
  1293.      confirmation through a dialog box.  PRINT  DATA  creates  a  file
  1294.      called  PROJ1.DAT  that  contains all the vertices of all objects
  1295.      in the room.  CANCEL can  be  chosen  to  cancel  any  operation.
  1296.      Choose QUIT to end the program.
  1297.  
  1298.           Human  factors  were  taken  into consideration when writing
  1299.      this program.  At all times,  a  message  box  is  shown  at  the
  1300.      bottom  of  the screen to guide the user during program operation
  1301.      and to  display  error  messages.    The  dialog  box  asks   for
  1302.      confirmation.   The  dialog  box  is  a  good  example of Turbo's
  1303.      getimage() and putimage() functions.
  1304.  
  1305.           All object information is stored in a linked list.   When  a
  1306.      user  creates  a new object, it is placed at the end of the list.
  1307.      When an object is deleted, it is also deleted from the list.
  1308.  
  1309.           Finally, take note of how  pick  correlation  is  performed.
  1310.  
  1311.                                                                    Page  26
  1312.  
  1313.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1314.  
  1315.      Pick  correlation  refers  to associating a mouse button click to
  1316.      an object or an area on the screen.  Each area  has  an  "extent"
  1317.      or rectangular  boundary  associated  with  it.    When  the user
  1318.      clicks on the CREATE button, the  program  must  determine  which
  1319.      button has  been  chosen  and take appropriate action.  Note that
  1320.      choosing an overlapping object in the room will return  only  the
  1321.      object on  the top.  More extensive programming would be required
  1322.      to resolve ambiguous clicks.
  1323.  
  1324.      [IN CLOSING]
  1325.  
  1326.           I believe this program will give you a good  feel  for  some
  1327.      basic graphics  techniques  and  Turbo  C's implementation.  Next
  1328.      month  I  will  present  a  simple  paint   program   that   will
  1329.      demonstrate  pull-  down menus, "rubber banding" techniques, fill
  1330.      patterns, and mouse cursor programming.
  1331.  
  1332.                                                                    Page  27
  1333.  
  1334.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1335.      =====================================================================
  1336.      ARTICLE      SUBMISSION       STANDARDS       AND       ADDRESSES
  1337.      =====================================================================
  1338.  
  1339.           As  I have repeatedly stated in this newsletter and previous
  1340.      issues, I would like to see user-submitted articles,  reviews  or
  1341.      questions.   Listed  below  are  the  standards  that  should  be
  1342.      followed to make my job easier as an editor.
  1343.  
  1344.            - Articles should be submitted in a ASCII non-formatted
  1345.              file.  (Margins 0-65 PLEASE)
  1346.  
  1347.            - If the article include code fragments as examples. Then
  1348.              you can include the entire source file if you like for
  1349.              inclusion with the newsletter.
  1350.  
  1351.            - Book or magazine reviews should follow the same format,
  1352.              that is outlined in this issue.  The publisher, author,
  1353.              title, and ISBN number are a must.
  1354.  
  1355.            - Compiler/and or product reviews, should include the
  1356.              version number and manufacture.  If possible, reviews
  1357.              should include a sample program with benchmarks.
  1358.  
  1359.           If you have any questions you can contact me at the
  1360.      address's included on the next page.
  1361.  
  1362.                                                                    Page  28
  1363.  
  1364.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1365.      =====================================================================
  1366.      HOW YOU CAN REACH THE AUTHORS OF C NEWS
  1367.      =====================================================================
  1368.  
  1369.             ADDRESSES
  1370.  
  1371.             The C BBS is located at:
  1372.  
  1373.             C BBS
  1374.             % BCL Limited
  1375.             P.O. Box 9162
  1376.             McLean VA, 22102
  1377.  
  1378.             or you can send netmail to:
  1379.  
  1380.             1:109/713
  1381.  
  1382.             or MCI Mail to:  BCL Limited
  1383.  
  1384.                                                                    Page  29
  1385.  
  1386.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1387.      =====================================================================
  1388.                             DISTRIBUTION POINTS
  1389.      =====================================================================
  1390.  
  1391.       Board Name               Number         Net/Node       Sysop
  1392.  
  1393.       *** UNITED STATES ***
  1394.  
  1395.       C BBS               (703) 644-6478      1:109/713      Barry Lynch
  1396.       McLean, VA
  1397.  
  1398.       Eastern C Board     (201) 247-6748      1:107/335      Todd Lehr
  1399.  
  1400.       Exec-PC             (414) 964-5160        ..           Bob Mahoney
  1401.       Milwaukee, WI
  1402.  
  1403.       TAMIAMI             (813) 793-2392                     Gerhard Barth
  1404.       Naples, FL
  1405.  
  1406.       Sound of Music      (516) 536-8723(2400)               Paul Waldinger
  1407.                           (516) 536-6819(9600 Hayes V)
  1408.  
  1409.       *** CANADA ***
  1410.  
  1411.       Another BBS System  (416) 465-7752      1:148/208      Mark Bowman
  1412.       Toronto, Canada
  1413.  
  1414.       *** EUROPE ***
  1415.  
  1416.       Fido_N1_1               31-8350-37156     2:500/1        Henk Wevers
  1417.       The Netherlands
  1418.  
  1419.       DUBBS BBS               353-1-885634       n/a           Stephen Kearon
  1420.       Dublin, Ireland
  1421.  
  1422.       *** AUSTRALIA ***
  1423.  
  1424.       Sentry BBS              02-428-4687       ...            Trev Roydhouse
  1425.              (300-2400) Non-Mail Times
  1426.              (300-19,200) Mail Hour (Trailblazer)
  1427.  
  1428.                                                                    Page  30
  1429.  
  1430.     C NEWS Vol. 1  Issue 13                                December 27, 1988
  1431.      =====================================================================
  1432.      USER RESPONSE FORM
  1433.      =====================================================================
  1434.  
  1435.              This form will be included as a regular feature in all future
  1436.          issues of C NEWS.
  1437.  
  1438.          What did you think of the content of this Issue?  _____________
  1439.  
  1440.          _______________________________________________________________
  1441.  
  1442.  
  1443.          What improvements can you think of that would make C News a
  1444.          better tool for the C Community?
  1445.  
  1446.          _______________________________________________________________
  1447.  
  1448.          _______________________________________________________________
  1449.  
  1450.  
  1451.          What is your favorite section or sections?  ___________________
  1452.  
  1453.          _______________________________________________________________
  1454.  
  1455.  
  1456.          What don't you like about C News?  ____________________________
  1457.  
  1458.          _______________________________________________________________
  1459.  
  1460.  
  1461.          Additional Comments:  _________________________________________
  1462.  
  1463.          _______________________________________________________________
  1464.  
  1465.          _______________________________________________________________
  1466.  
  1467.          _______________________________________________________________
  1468.  
  1469.  
  1470.                                                                    Page  31
  1471.  
  1472.  
  1473.